﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.IO;

namespace ETL.Tools
{
	public class Excel2DataSet
	{

		string sheetname = "";
		string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source='{0}';Extended Properties='Excel 8.0;HDR={1};IMEX=1'"; 

		public Excel2DataSet(string excelpath, string sheetname)
		{
			connectionString = string.Format(connectionString, excelpath, "1");
			this.sheetname = sheetname;
		}




		public DataTable GetExcelData()
		{
			DataTable table = new DataTable();

			System.Data.OleDb.OleDbDataAdapter adapter = new System.Data.OleDb.OleDbDataAdapter("SELECT * FROM [" + sheetname + "$]", connectionString);

			adapter.Fill(table);
			adapter.Dispose();

			return table;
		} 

	}
}
